﻿using IOP.SgrA;
using IOP.SgrA.GLSL;
using IOP.SgrA.SilkNet.Vulkan;
using IOP.SgrA.SilkNet.Vulkan.Scripted;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VkSample123
{
    [ShaderVersion("460")]
    [GLSLExtension("GL_ARB_separate_shader_objects : enable")]
    [GLSLExtension("GL_ARB_shading_language_420pack : enable")]
    public partial class SmoothFrag : GLSLFrag
    {
        [SampledImage(0, 0, DescriptorSetTarget.RenderObject)]
        public sampler2D Tex { get; set; }

        [ShaderInput(0)]
        public vec2 vTextureCoord {  get; set; }
        [FragOutput(0, false)]
        public vec4 OutColor { get; set; }
        public override void main()
        {
            float stStep = 512.0f;
            float scaleFactor = 1.0f / 9.0f;
            vec2[] offsets = new vec2[]
            {
                new vec2(-1.0f,-1.0f), new vec2(0.0f,-1.0f), new vec2(1.0f,-1.0f),
                new vec2(-1.0f,0.0f), new vec2(0.0f,0.0f), new vec2(1.0f,0.0f),
                new vec2(-1.0f,1.0f),new vec2(0.0f,1.0f),new vec2(1.0f,1.0f)
            };
            float[] kernelValues = new float[]
            {
                1.0f,1.0f,1.0f,
                1.0f,1.0f,1.0f,
                1.0f,1.0f,1.0f
            };
            vec4 sum = new vec4(0, 0, 0, 0);
            for (int i = 0; i < 9; i++)
            {
                sum = sum + kernelValues[i] * scaleFactor * texture(Tex, vTextureCoord + offsets[i] / stStep);
            }
            OutColor = sum;
        }
    }
}
